<?php  @session_start(); 
header("Content-type: text/x-csv");
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=leadprices.csv"); 


require_once '../../config/configuration.php';
require_once "../../includes/classes/Database.php";
require_once '../../model/leads.php';
require_once '../../model/state.php';
require_once '../../model/trade.php';
require_once '../../model/budget.php';
require_once '../../model/membershipplan.php';

$objLeads = new Model_Leads();
$objState = new Model_State();
$objjob = new Model_TRADE();
$objPlan = new Model_PLAN();
$budgetObj = new Model_Budget();

 if($_GET['search']!='')
 {
	 $search=$_GET['search'];
 }  
 
	$LeadDetails =  $objLeads->getAllLeads($$search);  
	$out = '';
	//$out .= 'Sr.No.,Region Name,Suburb Name,Postal Code,Job Type,Budget,Price,Membership Plan';
	$out .= 'Sr.No.,Region Name,Job Type,Budget,Price,Membership Plan';
	$out .= "\n";
	$srno = '1';
		for($i=0;$i<count($LeadDetails);$i++)
		{
			/*$explodeArray = @explode("-",$LeadDetails[$i]['budget']);
			$budgetname ='';
			$budgetname = "$".$explodeArray[0]." To $".$explodeArray[1];	*/
			$budgetdetail = $budgetObj->getBudgetDetailsById($LeadDetails[$i]['budget']);			
			$budgetname = "Under $".$budgetdetail['budget_name'];
			
			$getstatedetails=$objState->getStateDetailsById($LeadDetails[$i]["region_id"]);
			$regionname='';
			$regionname = $getstatedetails['state_name'];
			
			$getjobdetails=$objjob->getTradeCategoryDetailsById($LeadDetails[$i]["jobtype"]);			
			$jobtypename ='';
			$jobtypename = $getjobdetails['trade_category'];
			
			$suburbdetail = $objState->getPostalDetailsById($LeadDetails[$i]['suburb_id']);
			$suburbname = $suburbdetail['suburb'];
			
			$postalcode =$LeadDetails[$i]["postalcode"]; 
			$price = "$".$LeadDetails[$i]["price"];
			
			$getplandetail = $objPlan->getPlanDetailsById($LeadDetails[$i]['plan_id']);
			if($getplandetail['name']!='')
				$plan_name=$getplandetail['name'];

			
			$out .= '"'.$srno.'","'.$regionname.'","'.$jobtypename.'","'.$budgetname.'","'.$price.'","'.$plan_name.'"';
			$out .="\n";			
			$srno++;
		}

	echo $out;

?>